/**
 * @file   jps_normal.h
 * @brief  jump point search algorithm
 * @encode UTF-8
 * @log    date        author      notes
 *         2021.09.22  Jimmy       first version
 */
#ifndef __JPS_NORMAL_H_ 
#define __JPS_NORMAL_H_ 


#include <vector>
#include <memory>
#include <algorithm>
#include <cstring>
#include <thread>
#include <iostream>
#include "utils/maps.h"
#include "utils/map_list.h"

namespace jps_shell
{
    struct JpsPoint
    {
        Point pos;
        int   f;
        int   h;
        int   g;
        Point pre;     /* father point */
    };

    
}


class JpsNormal
{
    public:
        class greater_class
        {
            public:
                bool operator()(jps_shell::JpsPoint & a, jps_shell::JpsPoint & b)
                {
                    return (a.f > b.f);
                }
        };

        class Heap
        {
            private:
                std::vector<jps_shell::JpsPoint> mList;
            public:
                Heap()
                {
                    mList.clear();
                    make_heap(mList.begin(), mList.end(), greater_class());
                }

                ~Heap()
                {
                    mList.clear();
                }

                void clear()
                {
                    mList.clear();
                }

                void push(jps_shell::JpsPoint point)
                {
                    mList.push_back(point);
                    push_heap(mList.begin(), mList.end(), greater_class());
                }

                jps_shell::JpsPoint popMin()
                {
                    pop_heap(mList.begin(), mList.end(), greater_class());
                    jps_shell::JpsPoint node = mList.back();
                    mList.pop_back();
                    return node;
                }

                int size(void)
                {
                    return (int)(mList.size());
                }

                bool isEmpty(void)
                {
                    return (mList.empty());
                }
        };

    public:
        JpsNormal();
        ~JpsNormal();

    private:
        uint16_t mWidth;
        uint16_t mHeight;
        std::unique_ptr<MapList> mClosedList;
        std::unique_ptr<Heap> mOpenList;

    protected:
        uint16_t calcG(Point nPoint, Point startPoint);
        uint16_t calcH(Point nPoint, Point destPoint);

    
};




#endif	/* __JPS_NORMAL_H_ */
/* End of file */
